library(tidyverse)
library(stringr)
library(haven)

# Set the directory to the location of the replication data
setwd("")

D <- read_dta("Data_Raw/RAW-Flanders.dta")

D <- D %>%
     rename(duration = `Duration__in_seconds_`,
            V1_incivility = Q17, V2_incivility = Q77,
            V1_prejudice = Q19_1, V2_prejudice = Q78_1, 
            V1_opinion_diff = Q19_2, V2_opinion_diff = Q78_2, 
            V1_dislike_party = Q19_3, V2_dislike_party = Q78_3, 
            V1_discourage_pol = Q19_4, V2_discourage_pol = Q78_4, 
            V1_dissatisfied = Q19_5, V2_dissatisfied = Q78_5, 
            V1_troll_pol = Q19_6, V2_troll_pol = Q78_6, 
            V1_troll_user = Q19_7, V2_troll_user = Q78_7,
            
            conjoint1 = Q25, conjoint2 = Q47, conjoint3 = Q49,
            conjoint4 = Q51, conjoint5 = Q53,

            resp_ideology = LR, resp_gender = Geslacht,
            resp_party = Partijnaam_1_TEXT,
            resp_exposure_1 = Q30_1,
            resp_exposure_2 = Q30_12,
            resp_exposure_3 = Q30_13,
            resp_exposure_4 = Q30_14,
            resp_exposure_5 = Q30_15) %>%
     mutate(duration = as.numeric(duration))

D <- D %>%
     mutate(V1_incivility = recode(as.character(as_factor(V1_incivility)), "10 (Extreem respectloos)" = "10"),
            V1_incivility = recode(as.character(as_factor(V1_incivility)), "0 (Niet respectloos)" = "0"),
            V2_incivility = recode(as.character(as_factor(V2_incivility)), "10 (Extreem respectloos)" = "10"),
            V2_incivility = recode(as.character(as_factor(V2_incivility)), "0 (Niet respectloos)" = "0")) %>%
     mutate(concern_disrespect = recode(as.character(as_factor(Q32)), "Helemaal niet bezorgd" = 1,
                                             "Weinig bezorgd" = 2,
                                             "Ietwat bezorgd" = 3,
                                             "Matig bezorgd" = 4,
                                             "Uiterst bezorgd" = 5), 
            govt_action = recode(as.character(as_factor(Q36)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6)) %>%
     mutate(V1_incivility = as.numeric(V1_incivility),
            V2_incivility = as.numeric(V2_incivility)) %>%
     mutate(V1_prejudice = recode(as.character(as_factor(V1_prejudice)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V2_prejudice = recode(as.character(as_factor(V2_prejudice)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V1_opinion_diff = recode(as.character(as_factor(V1_opinion_diff)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V2_opinion_diff = recode(as.character(as_factor(V2_opinion_diff)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V1_dislike_party = recode(as.character(as_factor(V1_dislike_party)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V2_dislike_party = recode(as.character(as_factor(V2_dislike_party)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V1_discourage_pol = recode(as.character(as_factor(V1_discourage_pol)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V2_discourage_pol = recode(as.character(as_factor(V2_discourage_pol)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),

            V1_dissatisfied = recode(as.character(as_factor(V1_dissatisfied)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V2_dissatisfied = recode(as.character(as_factor(V2_dissatisfied)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V1_troll_pol = recode(as.character(as_factor(V1_troll_pol)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V2_troll_pol = recode(as.character(as_factor(V2_troll_pol)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V1_troll_user = recode(as.character(as_factor(V1_troll_user)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6),
            V2_troll_user = recode(as.character(as_factor(V2_troll_user)), "Helemaal oneens" = 1, "Oneens" = 2, "Eerder oneens" = 3, "Eerder eens" = 4, "Eens" = 5, "Helemaal eens" = 6)) %>%
     mutate(resp_ideology = recode(as.character(as_factor(resp_ideology)), "Links\n0" = "0", "Rechts\n10" = "10"),
            resp_gender = recode(as.character(as_factor(resp_gender)), "Vrouw" = "Female", "Man" = "Male", "Anders" = "Other"),
            resp_ideology = as.numeric(as.character(as_factor(resp_ideology))),
            resp_exposure_binary = ifelse(!is.na(resp_exposure_1) | !is.na(resp_exposure_2) | !is.na(resp_exposure_3) | !is.na(resp_exposure_4) | !is.na(resp_exposure_5), "Experienced social media harassment", "Has not experienced social media harassment"),
            resp_exposure_sexist_remarks = ifelse(is.na(resp_exposure_1), "No sexist remarks", "Sexist remarks"),
            resp_exposure_disrespectful_remarks = ifelse(is.na(resp_exposure_2), "No disrespectful remarks", "Disrespectful remarks"),
            resp_exposure_sexualized_images = ifelse(is.na(resp_exposure_3), "No humiliating/sexually charged images of oneself", "Humiliating/sexually charged images of oneself"),
            resp_exposure_violent_threats = ifelse(is.na(resp_exposure_4), "No violent threats", "Violent threats"),
            resp_exposure_persistent_harassment = ifelse(is.na(resp_exposure_5), "No persistent harassment", "Persistent harassment"),
            resp_personal_disrespect = recode(as.character(as_factor(Q31)), "Meerdere keren per dag" = "Several times a day",
                                                   "Ongeveer één keer per dag" = "About once a day",
                                                   "3 tot 6 dagen per week" = "3 to 6 days a week",
                                                   "1 tot 2 dagen per week" = "1 to 2 days a week",
                                                   "Om de paar weken" = "Every few weeks",
                                                   "Zelden" = "Less often",
                                                   "Nooit" = "Never"),
            resp_other_disrespect = recode(as.character(as_factor(Q37)), "Meerdere keren per dag" = "Several times a day",
                                                "Ongeveer één keer per dag" = "About once a day",
                                                "3 tot 6 dagen per week" = "3 to 6 days a week",
                                                "1 tot 2 dagen per week" = "1 to 2 days a week",
                                                "Om de paar weken" = "Every few weeks",
                                                "Zelden" = "Less often",
                                                "Nooit" = "Never")) %>%
     mutate(resp_ideology = as.character(as_factor(resp_ideology))) %>%
     mutate(resp_ideology_discrete = case_when(resp_ideology %in% 0:4 ~ "Left-wing",
                                               resp_ideology %in% 5 ~ "Center",
                                               resp_ideology %in% 6:10 ~ "Right-wing")) %>%
     mutate(resp_party = recode(as.character(as_factor(resp_party)), "Groen" = "Groen",
                                            "Voortui" = "Vooruit",
                                            "N-VA" = "N-VA",
                                            "CD&V" = "CD&V",
                                            "OpenVLD" = "Open Vld",
                                            "BR30" = "Other",
                                            "Cdenv" = "CD&V",
                                            "lokale partij" = "Other",
                                            "Lubbeek Leeft" = "Other",
                                            "Gemeentebelangen Open Vld" = "Open Vld",
                                            "cd&v" = "CD&V",
                                            "NV-A" = "N-VA",
                                            "Vooruit" = "Vooruit",
                                            "Nieuw Houtem" = "Other",
                                            "BeersePLus" = "Other",
                                            "Open Vld" = "Open Vld",
                                            "Vlaams Belang" = "Vlaams Belang",
                                            "vooruit" = "Vooruit",
                                            "PRO Boechout & Vremde" = "Other",
                                            "Spa" = "Vooruit",
                                            "Cd&v" = "CD&V",
                                            "ProKA" = "Other",
                                            "NAP" = "Other",
                                            "Open Diest" = "Other",
                                            "VOORUIT" = "Vooruit",
                                            "n-va" = "N-VA",
                                            "Nieuw" = "Other",
                                            "CD&V-CDB" = "CD&V",
                                            "LWD" = "Other",
                                            "cdenv" = "CD&V",
                                            "Samen een" = "Other",
                                            "CDenV" = "CD&V",
                                            "Open Zulte" = "Other",
                                            "Mensen met Mensen" = "Other",
                                            "Dynamisch - CD&V" = "CD&V",
                                            "open VLD" = "Open Vld",
                                            "Nva" = "N-VA",
                                            "dorpspartij" = "Other",
                                            "openVLD-stroop" = "Open Vld",
                                            "Groen+" = "Groen",
                                            "GIB" = "Other",
                                            "FORZA NINOVE" = "Other",
                                            "N va" = "N-VA",
                                            "Lokaal" = "Other",
                                            "NVA" = "N-VA",
                                            "CD&V Wichelen" = "CD&V",
                                            "groen" = "Groen",
                                            "CDnV" = "CD&V",
                                            "HOVE BEWEEGT" = "Other",
                                            "Vleteren Actief" = "Other",
                                            "Welzijn" = "Other",
                                            "Pro" = "Other",
                                            "Open VLD" = "Open Vld",
                                            "Dorpslijst Sander" = "Other",
                                            "Eendracht" = "Other",
                                            "OpenVld" = "Open Vld",
                                            "N-va" = "N-VA",
                                            "PVDA" = "PvdA",
                                            "Gemeentebelangen" = "Other",
                                            "Vroeger CD&V, nu lokale beweging SMS" = "CD&V",
                                            "open vld" = "Open Vld",
                                            "MENSEN MET MENSEN" = "Other",
                                            "Voluit" = "Vooruit",
                                            "Samen Vooruit" = "Vooruit",
                                            "Leefbaar Merksplas" = "Other",
                                            "LOOI.NU" = "Other",
                                            "Eenheid" = "Other",
                                            "PLUS" = "Other",
                                            "U. Wielsbeke" = "Other",
                                            "rkd" = "Other",
                                            "KWADRANTplus" = "Other",
                                            "Wij Hoeselt" = "Other",
                                            "Gavere Durft" = "Other",
                                            "Cd&V" = "CD&V",
                                            "Open vld" = "Open Vld",
                                            "Overijse2002-N-VA" = "N-VA",
                                            "iedereen borsbeek" = "Other",
                                            "PUUR-Diepenbeek" = "Other",
                                            "NieuwPittemEgem" = "Other",
                                            "Geef ik niet" = "Other",
                                            "VERJONGING" = "Other",
                                            "Open-VLD" = "Open Vld",
                                            "Deerlijk²" = "Other",
                                            "Pro Hoeilaart" = "Other",
                                            "Oost West" = "Other",
                                            "WELZIJN" = "Other",
                                            "pH7 positief Hove" = "Other",
                                            "VB" = "Vlaams Belang",
                                            "N-VA Kinrooi" = "N-VA",
                                            "Goen" = "Groen",
                                            "IDEE" = "Other",
                                            "ons dorp" = "Other",
                                            "lvp" = "Other",
                                            "Samen" = "Other",
                                            "vlaams belang" = "Vlaams Belang",
                                            "groenrood" = "Groen",
                                            "CD&v" = "CD&V",
                                            "nva" = "N-VA",
                                            "Oprecht Brecht" = "Other",
                                            "positief project" = "Other",
                                            "SamenVoorKruibeke" = "Other",
                                            "Iedereen Borsbeek" = "Other",
                                            "vld" = "Open Vld",
                                            "VOOR LATEM EN DEURLE" = "Other",
                                            "Bewust" = "Other",
                                            "Inzet" = "Other",
                                            "VLD" = "Open Vld",
                                            "Klaver" = "Other",
                                            "Cdv" = "CD&V",
                                            "CD§V" = "CD&V",
                                            "CD@V" = "CD&V",
                                            "Progressief Malle" = "Other",
                                            "CONTENT" = "Other",
                                            "NV A" = "N-VA",
                                            "VU  -  N-VA" = "N-VA",
                                            "Volksbelangen" = "Other",
                                            "pvda" = "PvdA",
                                            "GROEN" = "Groen",
                                            "Open Tervuren" = "Other",
                                            "Pvda" = "PvdA",
                                            "BR" = "Other",
                                            "Vlim.be" = "Other",
                                            "Dorpslijst Sander!" = "Other",
                                            "Hecht" = "Other",
                                            "PRO Hamont-Achel" = "Other",
                                            "Groen Hamme" = "Groen",
                                            "PLE" = "Other",
                                            "OVLD" = "Open Vld",
                                            "CDENV" = "CD&V",
                                            "Zellik-Relegem" = "Other",
                                            "Open-vld" = "Open Vld",
                                            "DNA! - Dilbeek Nu Anders!" = "Other",
                                            "Lijst ZellikRelegem" = "Other",
                                            "Respect" = "Other",
                                            "C.D.V" = "CD&V",
                                            "NCD" = "Other",
                                            "lijst burgemeenster" = "Other",
                                            "OPEN VLD" = "Open Vld",
                                            "gemeentebelangen" = "Other",
                                            "N-Va" = "N-VA",
                                            "Openbleef" = "Other",
                                            "CD&V Holsbeek" = "CD&V",
                                            "Herent21" = "Other",
                                            "Vldumont" = "Other",
                                            "Nijlen & U" = "Other",
                                            "Open VLD plus Oosterzele" = "Open Vld",
                                            "leefbaar merksplas" = "Other",
                                            "Pro Merchtem" = "Other",
                                            "cd Meerhout" = "CD&V",
                                            "Cd&V zandhoven" = "CD&V",
                                            "Ovld" = "Open Vld",
                                            "Inspraak.nu" = "Other",
                                            "Team Burgemeester" = "Other",
                                            "Pro Nieuwpoort" = "Other",
                                            " Cd&v" = "CD&V",
                                            " cd&v" = "CD&V",
                                            " NVA" = "N-VA"))

D$resp_party[D$resp_party %in% c(" ", "")] <- NA
D$pop_party <- D$resp_party


# CLEAN THE SINGLE VIGNETTE DATA

V <- tibble(country = "Belgium",
            respondent_type = "Politician",
            respondent_type_three = rep(D$respondent_type_three, 2),
            id = rep(paste("BE politician", 1:nrow(D)), 2),
            resp_gender = rep(D$resp_gender, 2),
            resp_party = rep(D$resp_party, 2),
            pop_party = rep(D$pop_party, 2),
            resp_ideology = rep(D$resp_ideology, 2),
            resp_ideology_discrete = rep(D$resp_ideology_discrete, 2),
            resp_exposure_binary = rep(D$resp_exposure_binary, 2),
            resp_exposure_sexist_remarks = rep(D$resp_exposure_sexist_remarks, 2),
            resp_exposure_disrespectful_remarks = rep(D$resp_exposure_disrespectful_remarks, 2),
            resp_exposure_sexualized_images = rep(D$resp_exposure_sexualized_images, 2),
            resp_exposure_violent_threats = rep(D$resp_exposure_violent_threats, 2),
            resp_exposure_persistent_harassment = rep(D$resp_exposure_persistent_harassment, 2),
            resp_personal_disrespect = rep(D$resp_personal_disrespect, 2),
            resp_other_disrespect = rep(D$resp_other_disrespect, 2),
            concern_disrespect = c(D$concern_disrespect, rep(NA, length(D$concern_disrespect))),
            govt_action = c(D$govt_action, rep(NA, length(D$govt_action))),

            incivility = c(D$V1_incivility, D$V2_incivility),
            task_number = rep(paste0("Task ", 1:2), each = nrow(D)),
            
            party_pol = c(D$`V_1_1_1`, D$`V_2_1_1`),
            woman_pol = c(D$`V_1_1_2`, D$`V_2_1_2`),
            text_pol = c(D$`V_1_1_3`, D$`V_2_1_3`),
            woman_user = c(D$`V_1_1_4`, D$`V_2_1_4`),
            text_user = c(D$`V_1_1_5`, D$`V_2_1_5`),
            gendered = c(D$`V_1_1_6`, D$`V_2_1_6`),
            
            prejudice = c(D$V1_prejudice, D$V2_prejudice),
            opinion_diff = c(D$V1_opinion_diff, D$V2_opinion_diff),
            dislike_party = c(D$V1_dislike_party, D$V2_dislike_party),
            discourage_pol = c(D$V1_discourage_pol, D$V2_discourage_pol),
            dissatisfied = c(D$V1_dissatisfied, D$V2_dissatisfied),
            troll_pol = c(D$V1_troll_pol, D$V2_troll_pol),
            troll_user = c(D$V1_troll_user, D$V2_troll_user))

V <- V %>%
     mutate(party_pol = recode(party_pol, "Party01" = "Vooruit", "Party02" = "CD&V", "Party03" = "N-VA"),
            poc_pol = recode(woman_pol, "Pol01" = "White politician", "Pol02" = "White politician", "Pol03" = "Person of Color politician",
                                        "Pol04" = "Person of Color politician", "Pol05" = "White politician", "Pol06" = "White politician",
                                        "Pol07" = "White politician", "Pol08" = "Person of Color politician", "Pol09" = "White politician",
                                        "Pol10" = "White politician", "Pol11" = "White politician", "Pol12" = "Person of Color politician",
                                        "Pol13" = "Person of Color politician", "Pol14" = "White politician", "Pol15" = "White politician",
                                        "Pol16" = "White politician", "Pol17" = "Person of Color politician", "Pol18" = "Person of Color politician"),
            woman_pol = recode(woman_pol, "Pol01" = "Woman politician", "Pol02" = "Woman politician", "Pol03" = "Woman politician",
                                          "Pol04" = "Woman politician", "Pol05" = "Woman politician", "Pol06" = "Woman politician",
                                          "Pol07" = "Woman politician", "Pol08" = "Woman politician", "Pol09" = "Woman politician",
                                          "Pol10" = "Man politician", "Pol11" = "Man politician", "Pol12" = "Man politician",
                                          "Pol13" = "Man politician", "Pol14" = "Man politician", "Pol15" = "Man politician",
                                          "Pol16" = "Man politician", "Pol17" = "Man politician", "Pol18" = "Man politician"),
            text_pol_group = recode(text_pol, "PolText01" = "Economy", "PolText02" = "Economy",
                                              "PolText03" = "Economy", "PolText04" = "Economy",
                                              "PolText05" = "Healthcare", "PolText06" = "Healthcare",
                                              "PolText07" = "Healthcare", "PolText08" = "Healthcare",
                                              "PolText09" = "Education", "PolText10" = "Education",
                                              "PolText11" = "Education", "PolText12" = "Education",
                                              "PolText13" = "Crime", "PolText14" = "Crime",
                                              "PolText15" = "Crime", "PolText16" = "Crime",
                                              "PolText17" = "National security", "PolText18" = "National security",
                                              "PolText19" = "National security", "PolText20" = "National security"),
            woman_user = recode(woman_user, "User01" = "Woman user", "User02" = "Woman user", "User03" = "Woman user",
                                            "User04" = "Woman user", "User05" = "Woman user", "User06" = "Woman user",
                                            "User07" = "Woman user", "User08" = "Woman user", "User09" = "Woman user",
                                            "User10" = "Man user", "User11" = "Man user", "User12" = "Man user",
                                            "User13" = "Man user", "User14" = "Man user", "User15" = "Man user",
                                            "User16" = "Man user", "User17" = "Man user", "User18" = "Man user"),
            gendered = recode(gendered, "Gendered01" = "Non-gendered text", "Gendered02" = "Gendered text"))

V$party_pol_copartisan <- "Non co-partisan"
V$party_pol_copartisan[(V$party_pol == "Vooruit" & toupper(V$resp_party) %in% c("VOORUIT", "VOORTUI")) |
                       (V$party_pol == "CD&V" & toupper(V$resp_party) %in% c("C.D.V", "CD§V", "CD@V", "CD&V", "CD&V WICHELEN", "CD&V-CDB", "CDENV", "CDNV", "CDV")) |
                       (V$party_pol == "N-VA" & toupper(V$resp_party) %in% c("N VA", "N-VA", "N-VA KINROOI", "NV A", "NV-A", "NVA"))] <- "Co-partisan"

V <- V %>% arrange(id)

write_csv(V, "Data_Cleaned/BE_Politician_Vignette.csv")


# CLEAN THE PAIRED CONJOINT DATA

C <- tibble(country = "Belgium",
            respondent_type = "Politician",
            respondent_type_three = rep(D$respondent_type_three, 10),
            id = rep(paste("BE politician", 1:nrow(D)), 10),
            duration = rep(D$duration, 10),
            resp_gender = rep(D$resp_gender, 10),
            resp_party = rep(D$resp_party, 10),
            resp_ideology_discrete = rep(D$resp_ideology_discrete, 10),
            resp_ideology = rep(D$resp_ideology, 10),
            resp_exposure_binary = rep(D$resp_exposure_binary, 10),

            task_number = paste0("Task ", rep(rep(1:5, each = 2), nrow(D))),

            chose_profile = c(as.numeric(as_factor(D$conjoint1) == "Gesprek A"),
                              as.numeric(as_factor(D$conjoint1) == "Gesprek B"),
                              as.numeric(as_factor(D$conjoint2) == "Gesprek A"),
                              as.numeric(as_factor(D$conjoint2) == "Gesprek B"),
                              as.numeric(as_factor(D$conjoint3) == "Gesprek A"),
                              as.numeric(as_factor(D$conjoint3) == "Gesprek B"),
                              as.numeric(as_factor(D$conjoint4) == "Gesprek A"),
                              as.numeric(as_factor(D$conjoint4) == "Gesprek B"),
                              as.numeric(as_factor(D$conjoint5) == "Gesprek A"),
                              as.numeric(as_factor(D$conjoint5) == "Gesprek B")),

            party_pol =  c(D$`F_1_1_1`, D$`F_1_2_1`, D$`F_2_1_1`, D$`F_2_2_1`, D$`F_3_1_1`, D$`F_3_2_1`, D$`F_4_1_1`, D$`F_4_2_1`, D$`F_5_1_1`, D$`F_5_2_1`),
            woman_pol =  c(D$`F_1_1_2`, D$`F_1_2_2`, D$`F_2_1_2`, D$`F_2_2_2`, D$`F_3_1_2`, D$`F_3_2_2`, D$`F_4_1_2`, D$`F_4_2_2`, D$`F_5_1_2`, D$`F_5_2_2`),
            text_pol =   c(D$`F_1_1_3`, D$`F_1_2_3`, D$`F_2_1_3`, D$`F_2_2_3`, D$`F_3_1_3`, D$`F_3_2_3`, D$`F_4_1_3`, D$`F_4_2_3`, D$`F_5_1_3`, D$`F_5_2_3`),
            woman_user = c(D$`F_1_1_4`, D$`F_1_2_4`, D$`F_2_1_4`, D$`F_2_2_4`, D$`F_3_1_4`, D$`F_3_2_4`, D$`F_4_1_4`, D$`F_4_2_4`, D$`F_5_1_4`, D$`F_5_2_4`),
            text_user =  c(D$`F_1_1_5`, D$`F_1_2_5`, D$`F_2_1_5`, D$`F_2_2_5`, D$`F_3_1_5`, D$`F_3_2_5`, D$`F_4_1_5`, D$`F_4_2_5`, D$`F_5_1_5`, D$`F_5_2_5`),
            gendered =   c(D$`F_1_1_6`, D$`F_1_2_6`, D$`F_2_1_6`, D$`F_2_2_6`, D$`F_3_1_6`, D$`F_3_2_6`, D$`F_4_1_6`, D$`F_4_2_6`, D$`F_5_1_6`, D$`F_5_2_6`))

C <- C %>%
     mutate(party_pol = recode(party_pol, "Party01" = "Vooruit", "Party02" = "CD&V", "Party03" = "N-VA"),
            poc_pol = recode(woman_pol, "Pol01" = "White politician", "Pol02" = "White politician", "Pol03" = "Person of Color politician",
                                        "Pol04" = "Person of Color politician", "Pol05" = "White politician", "Pol06" = "White politician",
                                        "Pol07" = "White politician", "Pol08" = "Person of Color politician", "Pol09" = "White politician",
                                        "Pol10" = "White politician", "Pol11" = "White politician", "Pol12" = "Person of Color politician",
                                        "Pol13" = "Person of Color politician", "Pol14" = "White politician", "Pol15" = "White politician",
                                        "Pol16" = "White politician", "Pol17" = "Person of Color politician", "Pol18" = "Person of Color politician"),
            woman_pol = recode(woman_pol, "Pol01" = "Woman politician", "Pol02" = "Woman politician", "Pol03" = "Woman politician",
                                          "Pol04" = "Woman politician", "Pol05" = "Woman politician", "Pol06" = "Woman politician",
                                          "Pol07" = "Woman politician", "Pol08" = "Woman politician", "Pol09" = "Woman politician",
                                          "Pol10" = "Man politician", "Pol11" = "Man politician", "Pol12" = "Man politician",
                                          "Pol13" = "Man politician", "Pol14" = "Man politician", "Pol15" = "Man politician",
                                          "Pol16" = "Man politician", "Pol17" = "Man politician", "Pol18" = "Man politician"),
            text_pol_group = recode(text_pol, "PolText01" = "Economy", "PolText02" = "Economy",
                                             "PolText03" = "Economy", "PolText04" = "Economy",
                                             "PolText05" = "Healthcare", "PolText06" = "Healthcare",
                                             "PolText07" = "Healthcare", "PolText08" = "Healthcare",
                                             "PolText09" = "Education", "PolText10" = "Education",
                                             "PolText11" = "Education", "PolText12" = "Education",
                                             "PolText13" = "Crime", "PolText14" = "Crime",
                                             "PolText15" = "Crime", "PolText16" = "Crime",
                                             "PolText17" = "National security", "PolText18" = "National security",
                                             "PolText19" = "National security", "PolText20" = "National security"),
            woman_user = recode(woman_user, "User01" = "Woman user", "User02" = "Woman user", "User03" = "Woman user",
                                            "User04" = "Woman user", "User05" = "Woman user", "User06" = "Woman user",
                                            "User07" = "Woman user", "User08" = "Woman user", "User09" = "Woman user",
                                            "User10" = "Man user", "User11" = "Man user", "User12" = "Man user",
                                            "User13" = "Man user", "User14" = "Man user", "User15" = "Man user",
                                            "User16" = "Man user", "User17" = "Man user", "User18" = "Man user"),
            gendered = recode(gendered, "Gendered01" = "Non-gendered text", "Gendered02" = "Gendered text"))

C$party_pol_copartisan <- "Non co-partisan"
C$party_pol_copartisan[C$party_pol == "Vooruit" & toupper(C$resp_party) %in% c("VOORUIT", "VOORTUI") |
                       C$party_pol == "CD&V" & toupper(C$resp_party) %in% c("C.D.V", "CD§V", "CD@V", "CD&V", "CD&V WICHELEN", "CD&V-CDB", "CDENV", "CDNV", "CDV") |
                       C$party_pol == "N-VA" & toupper(C$resp_party) %in% c("N VA", "N-VA", "N-VA KINROOI", "NV A", "NV-A", "NVA")] <- "Co-partisan"

C <- C %>% arrange(id)

write_csv(C, "Data_Cleaned/BE_Politician_Conjoint.csv")

